#include "stdafx.h"
#include "./tmButton.h"
#include "./tmMsgDispatcher.h"

using namespace GLES;

GLES::Bool tmButton::createFrom( char* nameNormal,char* namePressed,PointI& point,SizeI* size /*= NULL*/,RectI* pictRect /*= NULL*/ )
{
	E_Return(_btnNormal.createFromPVR(nameNormal));
	E_Return(_btnPressed.createFromPVR(namePressed));
	_rect = GLES::RectI(point.x,point.y,point.x + size->w,point.y + size->h);
	return true;
}

VOID tmButton::draw( GLES::Painter* painter ,RectI* parent)
{
	RectI o;
	GLES::Tool::translationRect(&o,&_rect,parent);
	GLES::Pict* p = _bPressed ? &_btnPressed : &_btnNormal;
	painter->drawPict(o,p);
}

VOID tmButton::onPressed( int x,int y )
{
	_bPressed = true;
	GLES::Singleton<tmMsgDispatcher>::GetSingleton()->invalidateRect(_rect,true);
}

VOID tmButton::onPressRelease( int x,int y )
{
	_bPressed = false;
	GLES::Singleton<tmMsgDispatcher>::GetSingleton()->invalidateRect(_rect,true);
	GLES::Singleton<tmMsgDispatcher>::GetSingleton()->postQuitMessage();
}